package FanShe2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestBoss {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //1.获取反射对象
        Class<?> bossCls = Class.forName("FanShe2.Boss");
        //2.实例化Boss对象
        Object o = bossCls.newInstance();

//        Method h1 = bossCls.getMethod("hi", String.class);
//        h1.invoke(o, "开发者教育");
        Method say = bossCls.getDeclaredMethod("say", int.class, String.class, char.class);
        say.setAccessible(true);//私有的也可以访问
        //应为私有??
        System.out.println("say.invoke(o, 50, \"aaa\", '男') = " + say.invoke(o, 50, "aaa", '男'));
        Object invoke = say.invoke(o, 100, "xxx", '女');
        System.out.println("invoke = " + invoke);


        Method m1 = bossCls.getDeclaredMethod("m1");
        Object invoke1 = m1.invoke(o);
        System.out.println("invoke1 = " + invoke1);
    }
}
